/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __QS_NetworkSystem_H__
#define __QS_NetworkSystem_H__

#include <QtCore/QMap>
#include <QtCore/QVector>
#include <QtCore/QDate>
#include <QtCore/QThread>

#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>

namespace QSThink
{
	
	class NetworkSystem;

	class NetworkListener
	{
	public:
		NetworkListener();
	protected:
		friend class NetworkSystem;
		virtual void OnNetworkReply(QNetworkReply* reply)=0;

	};

	//we use this to access the network
	class NetworkSystem 
		: public QObject
	{
		Q_OBJECT
	protected:
		//
		NetworkSystem();
	public:
		~NetworkSystem();


		static NetworkSystem& NetworkSystem::getSingleton()
		{
			static NetworkSystem inst;
			return inst;
		}

		QNetworkReply* httpGet(QString url);

	public slots:
		bool replyFinished(QNetworkReply* reply );
		bool OnReadyRead();
		bool slotError( QNetworkReply::NetworkError error );

	protected:
		QNetworkAccessManager* _netAccessMgr;
		QVector<NetworkListener*> _listeners;

	protected:
		friend class NetworkListener;
		void addListener(NetworkListener* listener);


	};

	


}
#endif
